import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/model/order_model.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 订单详情
///
class OrderInfo extends StatefulWidget {
  const OrderInfo({Key? key}) : super(key: key);

  @override
  State<OrderInfo> createState() => _OrderInfoState();
}

class _OrderInfoState extends State<OrderInfo> {

  late OrderModel item;

  @override
  void initState() {
    super.initState();
    item = OrderModel(
        username: '欧阳致远',
        time: '18:14',
        address: '北海市海城区广东南路同和水岸44栋6楼',
        days: 90,
        count: 15,
        overMinutes: 9,
        tecCost: 45.25,
        income: 78.36,
        orderNo: '12232964103521',
        createTime: '05-29 12:14',
        shops: [
          CommodityModel(name: '汉堡', iconUrl: '1.png'),
          CommodityModel(name: '可乐', iconUrl: '2.png'),
          CommodityModel(name: '鸡翅', iconUrl: '3.png'),
        ]);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('订单详情'),
      body: SingleChildScrollView(
        child: Container(
          margin: const EdgeInsets.only(top: Sizes.default10),
          padding:
          const EdgeInsets.symmetric(horizontal: Sizes.default15, vertical: Sizes.default15),
          decoration: const BoxDecoration(color: Colors.white),
          child: Column(
            children: [
              Container(
                height: Sizes.default30,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text.rich(
                      TextSpan(
                          text: '${item.username} ',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color363, fontSize: Sizes.default16),
                          children: [
                            WidgetSpan(
                                child: ToolsUtils.getUrlSvg(
                                    'https://cdn7.axureshop.com/demo/1525603/images/未完成订单__待处理__平台配送_/u5470.svg',
                                    width: 15,
                                    height: 14),
                                alignment: PlaceholderAlignment.middle)
                          ]),
                      textDirection: TextDirection.ltr,
                      textAlign: TextAlign.left,
                    ),
                    Wrap(
                      spacing: Sizes.default30,
                      children: [
                        ToolsUtils.getUrlSvg(
                            'https://cdn7.axureshop.com/demo/1525603/images/未完成订单__待处理__平台配送_/u5468.svg',
                            width: 13,
                            height: 16),
                        ToolsUtils.getUrlSvg(
                            'https://cdn7.axureshop.com/demo/1525603/images/未完成订单__待处理__平台配送_/u5467.svg',
                            width: 16,
                            height: 16)
                      ],
                    )
                  ],
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                child: Text(item.address,
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default13, color: ColorsUtils.color363)),
              ),
              Container(
                height: Sizes.default30,
                alignment: Alignment.centerLeft,
                child: Text(
                  '近${item.days}天第${item.count}次下单',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13),
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default15),
                child: Row(
                  children: [
                    Expanded(
                        child: Column(
                          children: [
                            Align(
                              alignment: Alignment.centerLeft,
                              child: Text('${item.time} 骑手已送达',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color363, fontSize: Sizes.default16)),
                            ),
                            Container(
                              alignment: Alignment.centerLeft,
                              margin: const EdgeInsets.only(top: Sizes.default10),
                              child: Wrap(
                                spacing: Sizes.default10,
                                children: [
                                  Container(
                                    constraints: const BoxConstraints.tightFor(width: 60, height: 18),
                                    alignment: Alignment.center,
                                    decoration: BoxDecoration(
                                        color:
                                        ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                                        borderRadius: BorderRadius.circular(2)),
                                    child: Text(
                                      '平台配送',
                                      style: StylesUtils.customTextStyle(
                                          color: ColorsUtils.colorWhite, fontSize: Sizes.default12),
                                    ),
                                  ),
                                  Text.rich(TextSpan(
                                      text: '骑手：张三丰 ',
                                      style: StylesUtils.customTextStyle(
                                          color: ColorsUtils.color797, fontSize: Sizes.default13),
                                      children: [
                                        WidgetSpan(
                                          child: Icon(
                                            AntdIcons.phoneFill,
                                            color: ColorsUtils.parseColorFromHexString('#999999'),
                                            size: Sizes.default14,
                                          ),
                                          alignment: PlaceholderAlignment.middle,
                                        )
                                      ]))
                                ],
                              ),
                            )
                          ],
                        )),
                    Center(
                      child: Text.rich(TextSpan(
                          text: '订单跟踪',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color006, fontSize: Sizes.default13),
                          children: [
                            WidgetSpan(
                                child: Icon(
                                  AntdIcons.right,
                                  size: Sizes.default14,
                                  color: ColorsUtils.colorFromHexString(ColorsUtils.color797),
                                ))
                          ])),
                    )
                  ],
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                margin: const EdgeInsets.symmetric(vertical: Sizes.default10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                        child: Wrap(
                          spacing: Sizes.default5,
                          children: [
                            ...item.shops
                                .map((e) => GFImageOverlay(
                                height: 60, width: 60, image: ToolsUtils.assetImage(e.iconUrl)))
                                .toList(),
                            Container(
                              height: 60,
                              width: 60,
                              alignment: Alignment.center,
                              child: ToolsUtils.getUrlSvg(
                                  'https://cdn7.axureshop.com/demo/1525603/images/未完成订单__待处理__平台配送_/u5489.svg',
                                  width: 20,
                                  height: 5),
                            )
                          ],
                        )),
                    Center(
                      child: Text.rich(TextSpan(
                          text: '共6件商品',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color006, fontSize: Sizes.default13),
                          children: [
                            WidgetSpan(
                                child: Icon(
                                  AntdIcons.right,
                                  size: Sizes.default14,
                                  color: ColorsUtils.colorFromHexString(ColorsUtils.color797),
                                ))
                          ])),
                    )
                  ],
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('发票信息',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color363)),
                    Text('不需要',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color797))
                  ],
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('技术服务费',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color363)),
                    Text('￥-${item.tecCost}',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color797))
                  ],
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('本单预计收入',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.color363)),
                    Text('￥${item.income}',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default13, color: ColorsUtils.colorCc0))
                  ],
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                margin: const EdgeInsets.only(top: Sizes.default25),
                child: Text('订单编号：${item.orderNo}',
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default12, color: ColorsUtils.color797)),
              ),
              Container(
                alignment: Alignment.centerLeft,
                margin: const EdgeInsets.only(top: Sizes.default5),
                child: Text.rich(TextSpan(
                    text: '交易快照：发生争议时，可作为判断依据',
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default12, color: ColorsUtils.color797),
                    children: [
                      WidgetSpan(
                          child: Icon(
                            AntdIcons.right,
                            size: Sizes.default13,
                            color: ColorsUtils.colorFromHexString(ColorsUtils.color797),
                          ))
                    ])),
              ),
              Container(
                alignment: Alignment.centerLeft,
                margin: const EdgeInsets.only(bottom: Sizes.default25, top: Sizes.default5),
                child: Text('下单时间：${item.createTime}',
                    style: StylesUtils.customTextStyle(
                        fontSize: Sizes.default12, color: ColorsUtils.color797)),
              ),
              Container(
                  alignment: Alignment.centerRight,
                  child: Wrap(
                    spacing: Sizes.default15,
                    children: [
                      SizedBox(
                        width: 100,
                        height: 30,
                        child: GFButton(
                          onPressed: () {},
                          text: '关闭交易',
                          textStyle: StylesUtils.customTextStyle(
                              fontSize: Sizes.default13, color: ColorsUtils.color797),
                          type: GFButtonType.outline,
                          borderSide: BorderSide(color: ColorsUtils.rgba(204, 204, 204, 1)),
                          padding: EdgeInsets.zero,
                        ),
                      ),
                      SizedBox(
                        width: 100,
                        height: 30,
                        child: GFButton(
                          onPressed: () {},
                          text: '打印接单',
                          textStyle: StylesUtils.customTextStyle(
                              fontSize: Sizes.default13, color: ColorsUtils.colorFf6),
                          type: GFButtonType.outline,
                          borderSide: BorderSide(color: ColorsUtils.rgba(255, 110, 83, 1)),
                          padding: EdgeInsets.zero,
                        ),
                      )
                    ],
                  )
              )
            ],
          ),
        ),
      ),
    );
  }
}
